@extends('admin.home.main')

@section('body')
<section id="main-content">

<section class="wrapper">
<h3>焦点图列表</h3>
<hr>
<div class="row mt">
  <div class="col-md-12">
  <form action="/admin/material/list" method="get">
    <select size="1" name="page_size" aria-controls="hidden-table-info" style="width:80px; height:34px;float:left; " class="form-control">
      <option value="0">请选择</option>
      @foreach($page_size_list as $ptm=>$pst)
        @if($pst == $page_size)
        <option value="{{$pst}}" selected="selected">{{$pst}}</option>
        @else
        <option value="{{$pst}}">{{$pst}}</option>
        @endif
      @endforeach
    </select>
    <input type="text" style="width:200px;float:left; margin-left:10px;" class="form-control" placeholder="请输入资料名称" name="keywords" id="keywords" value="{{$keywords}}">
    <button type="submit" id="search" style="float:left; margin-left:10px;" class="btn btn-success">搜索</button>
  </form>
  </div>
</div>


<!-- row -->
<div class="row mt">
  <div class="col-md-12">
    <div class="content-panel">
      <table class="table table-striped table-advance table-hover">
        <thead>
          <tr>
          	<th>#</th>
            <th>焦点图名称</th>
            <th>跳转地址</th>
            <th>位置</th>
            <th>是否上架</th>
            <th>添加时间</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          @foreach($mlist as $mtm=>$mst)
          <tr>
            <td>{{$mst->id}}</td>
            <td>{{$mst->banner_name}}</td>
            <td><a href="{{$mst->target_link}}">{{$mst->target_link}}</a></td>
            <td>
              {{$mst->position_name}}
            </td>
            <td>
              @if($mst->grounding == 'yes')
                已上架
                @else
                已下架
              @endif
            </td>
            <td>{{$mst->add_date}}</td>
            <td>
              <a href="/admin/material/edit/{{$mst->id}}" class="btn btn-primary btn-xs">编辑</a>
              <button type="botton" colid="{{$mst->id}}" class="btn btn-danger btn-xs col_del">删除</button>
              @if($mst->grounding == 'yes')
                <button type="button" colid="{{$mst->id}}" status="{{$mst->grounding}}" class="btn btn-warning btn-xs
                      col_status">下架焦点图</button>
                @else
                <button type="button" colid="{{$mst->id}}" status="{{$mst->grounding}}" class="btn btn-warning btn-xs
                      col_status">上架焦点图</button>
              @endif

            </td>
          </tr>
          @endforeach
        </tbody>
      </table>
    </div>
    <!-- /content-panel -->
    <div class="row-fluid">

      <div class="span6">
        <div class="dataTables_paginate paging_bootstrap pagination">
          <ul>{!! $mlist->render() !!}</ul>
        </div>
      </div>
    </div>
  </div>
  <!-- /col-md-12 -->
</div>
<!-- /row -->
</section>
</section>
<script type="text/javascript">
  $('.col_status').click(function(){
    var _colId = $(this).attr('colid');
    var status = $(this).attr('status');
    var _link = '';
    if(status == 'yes'){
      _link = '/admin/material/undercarriage/'+_colId;
    }else{
      _link = '/admin/material/grounding/'+_colId;
    }

    $.ajax({
      url:_link,
      type:'get',
      dataType:'json',
      success:function(msg){
        if(msg.code == 200){
          alert('操作成功');
        }else{
          alert('操作失败');
        }

        location.reload();
      }
    })
  })

  $('.col_del').click(function(){
    var _colId = $(this).attr('colid');
    var a = confirm('请确认是否要删除该banner');
    var t = $(this).parent().parent();

    if(a == true){
      $.ajax({
        'type':'get',
        'url':'/admin/material/del/'+_colId,
        'dataType':'json',
        success:function(msg){
          if(msg.code == 200){
            alert('删除成功');
          }else{
            alert('删除失败');
          }
          location.reload();
        }
      })
    }
  })
</script>
@endsection